<!--
 * @Description: In User Settings Edit
 * @Author: your name
 * @Date: 2019-07-30 20:02:30
 * @LastEditTime: 2020-02-28 11:25:38
 * @LastEditors: Please set LastEditors
 -->
<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>Hello APP</title>
    <link rel="stylesheet" type="text/css" href="../css/vant.css">
    <link rel="stylesheet" type="text/css" href="../css/base.css" />
    <script type="text/javascript" src="../script/jquery.js"></script>
    <script type="text/javascript" src="../script/layer/mobile/layer.js"></script>
    <script type="text/javascript" src="../script/vue.min.js"></script>
    <script type="text/javascript" src="../script/vant.min.js"></script>
    <script type="text/javascript" src="../script/fastclick.js"></script>
    <script type="text/javascript" src="../script/base.js"></script>
    <style>
        .listContent .van-row .van-col {
            color: #e6c678;
        }

        .van-cell__right-icon {
            color: #e6c678;
        }

        .add {
            position: fixed;
            bottom: 20px;
            right: 20px;
            width: 40px;
            height: 40px;
            border-radius: 40px;
            text-align: center;
            line-height: 44px;
            background: #e6c678;
            color: #fff;
            font-size: 20px;
        }

        .search {
            position: fixed;
            bottom: 80px;
            right: 20px;
            width: 40px;
            height: 40px;
            border-radius: 40px;
            text-align: center;
            line-height: 44px;
            background: #29292a;
            border: 1px solid #e6c678;
            color: #fff;
            font-size: 20px;
        }

        .van-popup {
            background-color: #090909;
            border: 1px solid #e6c678;
        }

        .van-popup__close-icon--top-right {
            color: #e6c678;
        }

        .van-cell {
            background-color: transparent;
            color: #e6c678;
        }
    </style>
</head>

<body>
    <div id="app" v-cloak>
        <div class="box">
            <van-list v-model="listLoading" :finished="listFinished" finished-text="没有更多了" @load="listOnLoad">
                <van-cell-group>
                    <van-cell style="background-color: rgba(0, 0, 0, 0.9);" @click="intoRow(row)"
                        v-for="row in dataList" center is-link>
                        <div class="listContent">
                            <van-row>
                                <van-col span="12">点检日期：{{row.BillDate}}</van-col>
                                <van-col span="12">点检单号：{{row.BillNO}}</van-col>
                                <van-col span="24">点检设备：{{row.EquipmentName}}</van-col>
                            </van-row>
                        </div>
                    </van-cell>
                </van-cell-group>
            </van-list>
        </div>

        <div class="add" @click="addNew">
            <van-icon name="plus"></van-icon>
        </div>
        <div class="search" @click="showSearch = true">
            <van-icon name="search"></van-icon>
        </div>

        <van-popup v-model="showSearch" position="bottom">
            <div style="padding-bottom: 10px;">
                <van-cell title="设备名称:" :value="filterData.EquipmentName" @click="openBaseScreen('机台')">
                </van-cell>
                <van-cell title="开始时间:" :value="filterData.beginTime" @click="handlerTime('start')">
                </van-cell>
                <van-cell title="结束时间:" :value="filterData.endTime" @click="handlerTime('end')">
                </van-cell>
            </div>
            <div class="btn-padding">
                <van-button color="#e6c678" type="primary" block style="border-radius: 0;" @click="handlerSearch">
                    查 &nbsp &nbsp &nbsp &nbsp &nbsp 询
                </van-button>
            </div>
        </van-popup>

        <van-popup v-model="showTime" position="bottom">
            <van-datetime-picker v-model="currentDate" type="date" title="选择年月日" @confirm="confirmTime"
                @cancel="showTime = false"></van-datetime-picker>
        </van-popup>
    </div>
</body>

<script type="text/javascript">
    var vm;
    apiready = function () {

        api.addEventListener({
            name: 'refreshDeviceCheck'
        }, function (ret, err) {
            vm.getDataList();
        })

        api.addEventListener({
            name: 'selectRow'
        }, function (ret, err) {
            var type = ret.value.type;
            var row = ret.value.row;
            if (type == '机台') {
                vm.filterData.EquipmentName = row.EquipmentName;
                vm.filterData.EquipmentID = row.EquipmentID;
            }
        })

        vm = new Vue({
            el: '#app',
            data: {
                listLoading: false,
                listFinished: true,
                dataList: [],
                showSearch: false,
                filterData: {
                    EquipmentName: api.pageParam.equipment.EquipmentName,
                    EquipmentID: api.pageParam.equipment.EquipmentID,
                    beginTime: getDay(-7),
                    endTime: getDay(0),
                    pageIndex: 1,
                    pageSize: 20,
                },
                deviceShow: false,
                deviceOctions: [],
                showTime: false,
                currentTimeStr: '',
                currentDate: new Date()
            },
            created: function () {
                var that = this;

                console.log('checkAPI', JSON.stringify(api.pageParam))
                if (window.localStorage.getItem('clientHeight') != 752) {
                    document.getElementById('app').style.zoom = 0
                } else {
                    document.getElementById('app').style.zoom = 1.5
                }

                that.getDataList();
            },
            methods: {
                listOnLoad() {
                    var that = this
                },
                addNew() {
                    var that = this
                    api.sendEvent({
                        name: 'resetBreadList',
                        extra: {
                            breadData: {
                                name: '设备点检明细',
                                url: 'deviceCheckDetail',
                                ZS_FunctionID: 0,
                                click: true
                            }
                        }
                    })
                    if (window.localStorage.getItem('clientHeight') != 752) {
                        api.openFrame({
                            name: 'deviceCheckDetail',
                            url: 'deviceCheckDetail.html',
                            rect: {
                                x: 0,
                                y: 115,
                                w: 'auto',
                                h: api.winHeight - 150 - api.safeArea.bottom
                            },
                            bgColor: '#29292a',
                            pageParam: api.pageParam
                        })
                    } else {
                        api.openFrame({
                            name: 'deviceCheckDetail',
                            url: 'deviceCheckDetail.html',
                            rect: {
                                x: 0,
                                y: 170,
                                w: 'auto',
                                h: api.winHeight - 230 - api.safeArea.bottom
                            },
                            bgColor: '#29292a',
                            pageParam: api.pageParam
                        })
                    }
                },
                intoRow(row) {
                    var that = this
                    api.sendEvent({
                        name: 'resetBreadList',
                        extra: {
                            breadData: {
                                name: '设备点检明细',
                                url: 'deviceCheckDetail',
                                ZS_FunctionID: 0,
                                click: true
                            }
                        }
                    })
                    if (window.localStorage.getItem('clientHeight') != 752) {
                        api.openFrame({
                            name: 'deviceCheckDetail',
                            url: 'deviceCheckDetail.html',
                            rect: {
                                x: 0,
                                y: 115,
                                w: 'auto',
                                h: api.winHeight - 150 - api.safeArea.bottom
                            },
                            bgColor: '#29292a',
                            pageParam: {
                                historyData: row,
                                pageParamMsg: api.pageParam
                            }
                        })
                    } else {
                        api.openFrame({
                            name: 'deviceCheckDetail',
                            url: 'deviceCheckDetail.html',
                            rect: {
                                x: 0,
                                y: 170,
                                w: 'auto',
                                h: api.winHeight - 230 - api.safeArea.bottom
                            },
                            bgColor: '#29292a',
                            pageParam: {
                                historyData: row,
                                pageParamMsg: api.pageParam
                            }
                        })
                    }
                },
                handlerSearch() {
                    var that = this
                    that.filterData.pageIndex = 1
                    that.getDataList()
                    that.showSearch = false
                },
                openBaseScreen: function (str) {
                    var that = this;
                    var obj;
                    if (str == '机台') {
                        obj = {
                            allowClear: false,
                            showSearch: true,
                            searchKey: '',
                            serverSearch: false,
                            searchBy: ['EquipmentName'],
                            isPaging: false,
                            type: str,
                            cmd: 'getZSEquipment',
                            param: {
                            }
                        }
                    }

                    api.openWin({
                        name: 'baseScreen',
                        url: 'common/baseScreen.html',
                        reload: true,
                        slidBackEnabled: false,
                        pageParam: obj
                    })
                },
                handlerTime(time) {
                    var that = this
                    that.currentTimeStr = time
                    that.showTime = true
                },
                confirmTime() {
                    var that = this
                    if (that.currentTimeStr == 'start') {
                        that.filterData.beginTime = APP.getFormatDate(that.currentDate)
                    } else {
                        that.filterData.endTime = APP.getFormatDate(that.currentDate)
                    }
                    that.showTime = false
                },
                getDataList: function () {
                    var that = this;
                    that.listLoading = true;
                    that.listFinished = false;
                    APP.ajax('EquipmentSpotCheckList', that.filterData, function (res) {
                        that.listLoading = false;
                        that.listFinished = true;
                        that.dataList = res.ds;
                    })
                },
                listOnLoad: function () {
                    var that = this;
                    that.filterData.pageIndex++;
                    APP.ajax('EquipmentSpotCheckList', that.filterData, function (res) {
                        that.listLoading = false;
                        if (res.ds.length == 0) {
                            that.listFinished = true;
                        }
                        that.dataList = that.dataList.concat(res.ds);
                    })
                },
            }
        })
    };

    function getDay(day) {

        var today = new Date();


        var targetday_milliseconds = today.getTime() + 1000 * 60 * 60 * 24 * day;

        today.setTime(targetday_milliseconds); //注意，这行是关键代码

        var tYear = today.getFullYear();

        var tMonth = today.getMonth();

        var tDate = today.getDate();

        tMonth = doHandleMonth(tMonth + 1);

        tDate = doHandleMonth(tDate);

        return tYear + "-" + tMonth + "-" + tDate;

    }

    function doHandleMonth(month) {

        var m = month;

        if (month.toString().length == 1) {

            m = "0" + month;

        }

        return m;

    }
</script>

</html>